<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        span {
            display: inline-block;
            width: 80px;
            height: 30px;
            background: #ccc;
            text-align: center;
            line-height: 30px;
            /* 当点击元素的时候会默认选中元素的内容，可以设置以下diamante，内容就不会被选择 */
            user-select: none;
        }
    </style>
</head>
<body>
    <input type="text" id="num">
    <span id="code"></span>
    <button id="btn">验证</button>
    <script src="./js/utils.js"></script>
    <script>
        // 验证码匹配
        // 思路：拿输入框的值和验证码的值进行比较，匹配就验证成功，否则验证失败
        code.innerHTML = randomNum(1000,9999);
        
        btn.onclick = function(){
            if(num.value === code.innerHTML){
                alert('验证成功')
            }else{
                alert('验证失败，请重新输入')
                code.innerHTML = randomNum(1000,9999);
            }
        }
        // 点击验证码可以更新验证码数字
        code.onclick = function(){
            this.innerHTML = randomNum(1000,9999);
        }
    </script>
</body>
</html>